route.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // app/api/branches/[branch]/[year]/[month]/days/route.js
  2. import { NextResponse } from "next/server";
  3. import { listDays } from "@/lib/storage";
  4. /**
  5. * GET /api/branches/[branch]/[year]/[month]/days
  6. *
  7. * Returns the list of day folders for a given branch, year, and month.
  8. * Example: /api/branches/NL01/2024/10/days → { days: ["01", "02", ...] }
  9. */
  10. export async function GET(request, ctx) {
  11. const { branch, year, month } = await ctx.params;
  12. console.log("[/api/branches/[branch]/[year]/[month]/days] params:", {
  13. branch,
  14. year,
  15. month,
  16. });
  17. if (!branch || !year || !month) {
  18. return NextResponse.json(
  19. { error: "branch, year oder month fehlt" },
  20. { status: 400 }
  21. );
  22. }
  23. try {
  24. const days = await listDays(branch, year, month);
  25. return NextResponse.json({ branch, year, month, days });
  26. } catch (error) {
  27. console.error("[/api/branches/[branch]/[year]/[month]/days] Error:", error);
  28. return NextResponse.json(
  29. { error: "Fehler beim Lesen der Tage: " + error.message },
  30. { status: 500 }
  31. );
  32. }
  33. }